<?php
/**
 * Create by 11li
 * Date 2020/1/13
 * Time 10:02
 *
 */

namespace app\api\controller\v1;


use app\common\controller\Api;
use app\common\service\PromoterService;
use app\common\service\StatusService;
use app\common\service\UserService;
use think\Exception;

class User extends Api
{
	
	/**
	 * 会员中心
	 */
	public function index()
	{
		$this->success('查询成功', $this->auth->getUserinfo());
	}
	
	
	/**
	 * 开通推广权限
	 */
	public function openPromoter() {
		$userId = $this->auth->id;
		$obj = new PromoterService();
		$res = $obj->openRole($userId);
		if($res !== false) {
			$this->success('开通成功', $this->auth->getUserinfo());
		} else {
			$this->error($obj->getError());
		}
	}
	
	/**
	 * 关注
	 */
	public function follow($id) {
		$obj = new UserService();
		try {
			$res = $obj->follow($this->auth->id, $id);
			$this->success('关注成功');
		} catch (Exception $e) {
			$this->error($e->getMessage());
		}
	}
}